package main

import (
	"fmt"
	"image"
	_ "image/jpeg"
	"image/png"
	_ "image/png"
	"os"
	cogen "photographcover"
	colorstyle "photographcover/color"
)

func main() {
	colorstyle.InitColor()
	rgbarrr := []int{0, 0, 0}
	fontrgb := []int{255, 255, 255}
	// 读取背景图片
	input, _ := os.Open("C:\\Users\\1\\Desktop\\tem\\img\\bg1.png")
	defer input.Close()
	fontFilePath := "C:\\Users\\1\\Desktop\\tem\\font\\AlimamaDaoLiTi.ttf"
	fontData, _ := os.ReadFile(fontFilePath)
	bgimg, _, err := image.Decode(input)
	if err != nil {
		panic(err)
	}
	c := image.Config{
		Width:  bgimg.Bounds().Max.X,
		Height: bgimg.Bounds().Max.Y,
	}
	for i := 1; i < 3; i++ {
		saveFile := fmt.Sprintf("C:\\Users\\1\\Desktop\\tem\\tem%d.png", i)
		generator(fontData, rgbarrr, fontrgb, bgimg, c, saveFile)
	}
}

func generator(fontData []byte, rgbarrr []int, fontrgb []int, bgimg image.Image, c image.Config, saveFile string) {
	img := cogen.CoverGen2(
		cogen.WithTitle("阿萨德跨奥施康定了解阿里看似简单是"),
		cogen.WithFontData(fontData),
		cogen.WithFontSize(100),
		cogen.WithCoverRGB(rgbarrr),
		cogen.WithFontRGB(fontrgb),
		cogen.WithBgImage(bgimg),
		cogen.WithBgImageConfig(c),
		cogen.WithMaxWordWidth(1000),
		cogen.WithX(700),
		cogen.WithY(370),
	)
	file, _ := os.Create(saveFile)
	defer file.Close()
	err2 := png.Encode(file, img)
	if err2 != nil {
		panic(err2)
	}
}
